package com.wangyadong.hobby.thread.lesson2withconcurrent;

import com.wangyadong.hobby.thread.Holder;

import java.util.stream.IntStream;

/**
 * Holder
 * <p/>
 * Class at risk of failure if not properly published
 *
 * @author Brian Goetz and Tim Peierls
 */
public class HolderTest {
    private Holder holder;


    public Holder getInstance() {
        if (holder == null) {
            holder = new Holder(-1);
        }
        return holder;
    }

    public static void main(String[] args) {
        HolderTest test = new HolderTest();
        IntStream.rangeClosed(0, 20000).forEach(i -> {
            new Thread(() -> {
                Holder holder = test.getInstance();
                holder.assertSanity();
            }).start();
        });
    }

}